package com.zhangsun.springRabbitMq.consumer;

import com.zhangsun.springRabbitMq.common.RabbitMqTopicConstant;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Topic模式消费者
 */
@Component
public class TopicConsumer {

    /**
     * 消息执行
     *
     * @param msg 参数
     */
    @RabbitListener(queues = RabbitMqTopicConstant.TOPIC_HELLO_WORLD_1)
    public void receiveTopic1(String msg) {
        System.out.println(RabbitMqTopicConstant.TOPIC_HELLO_WORLD_1 + "：" + msg);
    }

    /**
     * 消息执行
     *
     * @param msg 参数
     */
    @RabbitListener(queues = RabbitMqTopicConstant.TOPIC_HELLO_WORLD_2)
    public void receiveTopic2(String msg) {
        System.out.println(new Date());
        try {
            Thread.currentThread().sleep(5000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
        System.out.println(new Date());
        System.out.println(RabbitMqTopicConstant.TOPIC_HELLO_WORLD_2 + "：" + msg);
    }

}
